package com.liush.srb.core.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liush.srb.base.result.ResponseVo;
import com.liush.srb.core.pojo.entity.Borrower;
import com.liush.srb.core.pojo.vo.BorrowerApprovalVO;
import com.liush.srb.core.pojo.vo.BorrowerDetailVO;
import com.liush.srb.core.pojo.vo.BorrowerVO;
import com.liush.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: liush
 * @CreateTime: 2023-04-06  21:18
 * @Description: 借款人 前端控制器
 */
@Api(tags = "admin借款人")
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

    @Resource
    BorrowerService borrowerService;

    @ApiOperation("条件分页查询借款人列表")
    @GetMapping("{pageNum}/{pageSize}")//  /admin/core/borrower/1/3?key=xxxx
    public ResponseVo list(@PathVariable("pageNum") Integer pageNum,
                           @PathVariable("pageSize") Integer pageSize,
                           String key) {
        Page page = new Page<Borrower>(pageNum, pageSize);
        borrowerService.listBorrowersByKey(page, key);
        return ResponseVo.ok().data("page", page);
    }

    @ApiOperation("根据借款人id查询借款人详情")
    @GetMapping("{id}")
    public ResponseVo getById(@PathVariable("id") Long id) {
        BorrowerDetailVO borrowerDetailVO = borrowerService.queryBorrowerVOById(id);
        return ResponseVo.ok().data("item", borrowerDetailVO);
    }

    @ApiOperation("借款人审批")
    @PostMapping("approval")
    public ResponseVo approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO) {
        borrowerService.approval(borrowerApprovalVO);
        return ResponseVo.ok();
    }
}
